﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class RoomBussiness: IDbServices<bool,int, TblRoom>
    {
        BookingDB db = new BookingDB();
        public bool AddData(TblRoom e)
        {
            try
            {
                db.TblRooms.Add(e);
                db.SaveChanges();
                return true;
            }
            catch (DbEntityValidationException ex)
            {
                Console.Write(ex.Message);
                return false;
            }
        }

        public bool UpdateData(TblRoom e)
        {
            try
            {
                db.Entry(e).State = EntityState.Modified;
                db.SaveChanges();
                return true;
            }
            catch (ValidationException ex)
            {

                return false;
            }
        }

        public bool DeleteData(int k)
        {
            TblRoom objRoom = new TblRoom();
            objRoom = db.TblRooms.Find(k);
            try
            {
                db.TblRooms.Remove(objRoom);
                db.SaveChanges();
                return true;

            }
            catch (DbUpdateConcurrencyException)
            {

                return false;
            }
         
        }

        public TblRoom GetDataByKey(int k)
        {
            try
            {
                return db.TblRooms.Find(k);
            }
            catch (Exception)
            {

                return null;
            }
        }

        public List<TblRoom> GetAll()
        {
            try
            {
                return db.TblRooms.ToList<TblRoom>();
            }
            catch (Exception)
            {

                return null;
            }
        }
    }
}
